<!DOCTYPE html>
<html><head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <link rel="alternate" type="application/rss+xml" href="/mybatis-plus/index.xml" title="h-book" />
    <link rel="canonical" href="/mybatis-plus/">

    <title>
        
        Mybatis Plus | h-book
        
    </title>

    
    <link href="/css/fontawesome.min.css" rel="stylesheet">

    
    <link rel="stylesheet" href="/css/ace.min.css">

    

    

</head>
<body><nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow sticky-top" id="navbarMain">
    <div class="container">
        <div>
            <a class="navbar-brand" href="/">
                
                h-book
            </a>
        </div>
    </div>
</nav>
<div class="container-fluid">
            <div class="row">

                <div class="docs-sidenav order-0 col-12 col-md-3 col-lg-2 col-xl-2 position-sticky border-right"><nav class="navbar navbar-expand-md navbar-light pl-0">
    <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#sidenav-left-collapse" aria-controls="sidenav-left-collapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

     <div class="collapse navbar-collapse align-items-start flex-column" id="sidenav-left-collapse">
            <form class="form-inline my-2 my-lg-0 searchbox">
                <input class="form-control mr-sm-2 w-100" data-search-input id="search-by" type="text" placeholder="Search">
            </form>

        

         <ul class="navbar-nav flex-column pt-3">
    <li data-nav-id="/hugo/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/hugo/"><h6>Hugo</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/hugo/init/" class="nav-item my-1">
                
                
                  <a href="/hugo/init/" class="nav-link p-0">
                    init
                  </a>
                
        </li>
        <li data-nav-id="/hugo/add-page/" class="nav-item my-1">
                
                
                  <a href="/hugo/add-page/" class="nav-link p-0">
                    add-page
                  </a>
                
        </li>
        <li data-nav-id="/hugo/edit-skill/" class="nav-item my-1">
                
                
                  <a href="/hugo/edit-skill/" class="nav-link p-0">
                    edit-skill
                  </a>
                
        </li>
        <li data-nav-id="/hugo/publish/" class="nav-item my-1">
                
                
                  <a href="/hugo/publish/" class="nav-link p-0">
                    publish
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/android/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/android/"><h6>Android</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/android/install/" class="nav-item my-1">
                
                
                  <a href="/android/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/android/create-project/" class="nav-item my-1">
                
                
                  <a href="/android/create-project/" class="nav-link p-0">
                    create project
                  </a>
                
        </li>
        <li data-nav-id="/android/import-material/" class="nav-item my-1">
                
                
                  <a href="/android/import-material/" class="nav-link p-0">
                    import material
                  </a>
                
        </li>
        <li data-nav-id="/android/start-page/" class="nav-item my-1">
                
                
                  <a href="/android/start-page/" class="nav-link p-0">
                    startpage
                  </a>
                
        </li>
        <li data-nav-id="/android/i18n/" class="nav-item my-1">
                
                
                  <a href="/android/i18n/" class="nav-link p-0">
                    i18n
                  </a>
                
        </li>
        <li data-nav-id="/android/nav-flat-page/" class="nav-item my-1">
                
                
                  <a href="/android/nav-flat-page/" class="nav-link p-0">
                    nav flat page
                  </a>
                
        </li>
        <li data-nav-id="/android/activity/" class="nav-item my-1">
                
                
                  <a href="/android/activity/" class="nav-link p-0">
                    Activity
                  </a>
                
        </li>
        <li data-nav-id="/android/db/" class="nav-item my-1">
                
                
                  <a href="/android/db/" class="nav-link p-0">
                    DB
                  </a>
                
        </li>
        <li data-nav-id="/android/dialog/" class="nav-item my-1">
                
                
                  <a href="/android/dialog/" class="nav-link p-0">
                    Dialog
                  </a>
                
        </li>
        <li data-nav-id="/android/fragment/" class="nav-item my-1">
                
                
                  <a href="/android/fragment/" class="nav-link p-0">
                    Fragment
                  </a>
                
        </li>
        <li data-nav-id="/android/jetpack/" class="nav-item my-1">
                
                
                  <a href="/android/jetpack/" class="nav-link p-0">
                    Jetpack
                  </a>
                
        </li>
        <li data-nav-id="/android/material/" class="nav-item my-1">
                
                
                  <a href="/android/material/" class="nav-link p-0">
                    Material
                  </a>
                
        </li>
        <li data-nav-id="/android/storage/" class="nav-item my-1">
                
                
                  <a href="/android/storage/" class="nav-link p-0">
                    Storage
                  </a>
                
        </li>
        <li data-nav-id="/android/%E5%9B%BE%E6%A0%87/" class="nav-item my-1">
                
                
                  <a href="/android/%E5%9B%BE%E6%A0%87/" class="nav-link p-0">
                    图标
                  </a>
                
        </li>
        <li data-nav-id="/android/store/" class="nav-item my-1">
                
                
                  <a href="/android/store/" class="nav-link p-0">
                    Store
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/blender/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/blender/"><h6>Blender</h6></a>
        
    </li>
    <li data-nav-id="/bootstrap/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/bootstrap/"><h6>BootStrap</h6></a>
        
    </li>
    <li data-nav-id="/centos7/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/centos7/"><h6>Centos7</h6></a>
        
    </li>
    <li data-nav-id="/dlna/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dlna/"><h6>DLNA</h6></a>
        
    </li>
    <li data-nav-id="/docker/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/docker/"><h6>Docker</h6></a>
        
    </li>
    <li data-nav-id="/dubbo/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dubbo/"><h6>Dubbo</h6></a>
        
    </li>
    <li data-nav-id="/ffmpeg/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/ffmpeg/"><h6>FFmpeg</h6></a>
        
    </li>
    <li data-nav-id="/git/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/git/"><h6>Git</h6></a>
        
    </li>
    <li data-nav-id="/gitbook/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gitbook/"><h6>Gitbook</h6></a>
        
    </li>
    <li data-nav-id="/gitlab/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/gitlab/"><h6>Gitlab</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/gitlab/runner/" class="nav-item my-1">
                
                
                  <a href="/gitlab/runner/" class="nav-link p-0">
                    Runner
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/gradle/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gradle/"><h6>Gradle</h6></a>
        
    </li>
    <li data-nav-id="/java/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/java/"><h6>Java</h6></a>
        
    </li>
    <li data-nav-id="/jenkins/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/jenkins/"><h6>Jenkins</h6></a>
        
    </li>
    <li data-nav-id="/kubernetes/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/kubernetes/"><h6>Kubernetes</h6></a>
        
    </li>
    <li data-nav-id="/mybatis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis/"><h6>Mybatis</h6></a>
        
    </li>
    <li data-nav-id="/mybatis-plus/" class="nav-item my-1 active
        ">
        
        
          <a class="nav-link p-0" href="/mybatis-plus/"><h6>Mybatis Plus</h6></a>
        
    </li>
    <li data-nav-id="/mysql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mysql/"><h6>MySQL</h6></a>
        
    </li>
    <li data-nav-id="/nodejs/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/nodejs/"><h6>Node.js</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/nodejs/npm/" class="nav-item my-1">
                
                
                  <a href="/nodejs/npm/" class="nav-link p-0">
                    NPM
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/postgresql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/postgresql/"><h6>PostgreSQL</h6></a>
        
    </li>
    <li data-nav-id="/redis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/redis/"><h6>Redis</h6></a>
        
    </li>
    <li data-nav-id="/samba/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/samba/"><h6>Samba</h6></a>
        
    </li>
    <li data-nav-id="/sql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/sql/"><h6>SQL</h6></a>
        
    </li>
    <li data-nav-id="/ue5/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/ue5/"><h6>UE5</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/ue5/install/" class="nav-item my-1">
                
                
                  <a href="/ue5/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/ue5/uninstall/" class="nav-item my-1">
                
                
                  <a href="/ue5/uninstall/" class="nav-link p-0">
                    uninstall
                  </a>
                
        </li>
        <li data-nav-id="/ue5/qa/" class="nav-item my-1">
                
                
                  <a href="/ue5/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity/"><h6>Unity</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity/install/" class="nav-item my-1">
                
                
                  <a href="/unity/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/unity/scene/" class="nav-item my-1">
                
                
                  <a href="/unity/scene/" class="nav-link p-0">
                    scene
                  </a>
                
        </li>
        <li data-nav-id="/unity/inspector/" class="nav-item my-1">
                
                
                  <a href="/unity/inspector/" class="nav-link p-0">
                    inspector
                  </a>
                
        </li>
        <li data-nav-id="/unity/assets/" class="nav-item my-1">
                
                
                  <a href="/unity/assets/" class="nav-link p-0">
                    assets
                  </a>
                
        </li>
        <li data-nav-id="/unity/audio-source/" class="nav-item my-1">
                
                
                  <a href="/unity/audio-source/" class="nav-link p-0">
                    audio source
                  </a>
                
        </li>
        <li data-nav-id="/unity/camera/" class="nav-item my-1">
                
                
                  <a href="/unity/camera/" class="nav-link p-0">
                    camera
                  </a>
                
        </li>
        <li data-nav-id="/unity/script/" class="nav-item my-1">
                
                
                  <a href="/unity/script/" class="nav-link p-0">
                    script
                  </a>
                
        </li>
        <li data-nav-id="/unity/prefabs/" class="nav-item my-1">
                
                
                  <a href="/unity/prefabs/" class="nav-link p-0">
                    prefabs
                  </a>
                
        </li>
        <li data-nav-id="/unity/physics/" class="nav-item my-1">
                
                
                  <a href="/unity/physics/" class="nav-link p-0">
                    physics
                  </a>
                
        </li>
        <li data-nav-id="/unity/skybox/" class="nav-item my-1">
                
                
                  <a href="/unity/skybox/" class="nav-link p-0">
                    skybox
                  </a>
                
        </li>
        <li data-nav-id="/unity/particle-system/" class="nav-item my-1">
                
                
                  <a href="/unity/particle-system/" class="nav-link p-0">
                    particle system
                  </a>
                
        </li>
        <li data-nav-id="/unity/shortcut-keys/" class="nav-item my-1">
                
                
                  <a href="/unity/shortcut-keys/" class="nav-link p-0">
                    shortcut keys
                  </a>
                
        </li>
        <li data-nav-id="/unity/qa/" class="nav-item my-1">
                
                
                  <a href="/unity/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-beginner/"><h6>Unity 2D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-beginner/init-and-move/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/init-and-move/" class="nav-link p-0">
                    Init &amp; Move
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/map/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/map/" class="nav-link p-0">
                    Map
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/data/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/data/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/animate/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/animate/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/bullet/" class="nav-link p-0">
                    Bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/cinemachine/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/cinemachine/" class="nav-link p-0">
                    Cinemachine
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/particle/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/particle/" class="nav-link p-0">
                    Particle
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/npc/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/npc/" class="nav-link p-0">
                    NPC
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-game-kit/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-game-kit/"><h6>Unity 2D Game Kit</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-game-kit/record/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-game-kit/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-3d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-3d-beginner/"><h6>Unity 3D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-3d-beginner/init/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/level/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/level/" class="nav-link p-0">
                    Level
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/nav/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/nav/" class="nav-link p-0">
                    Nav
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/render-pipeline/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/render-pipeline/" class="nav-link p-0">
                    Render Pipeline
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/postprocessing/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/postprocessing/" class="nav-link p-0">
                    PostProcessing
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/enemy/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/enemy/" class="nav-link p-0">
                    Enemy
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-link p-0">
                    建模工具
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-arpg/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-arpg/"><h6>Unity ARPG</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-arpg/init/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/role-state-machine/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/role-state-machine/" class="nav-link p-0">
                    Role State Machine
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/api-piece/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/api-piece/" class="nav-link p-0">
                    API Piece
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-animation/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-animation/"><h6>Unity Creativecore Animation</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-animation/door/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/door/" class="nav-link p-0">
                    Door
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-animation/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-lighting/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-lighting/"><h6>Unity Creativecore Lighting</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-lighting/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-lighting/outdoor/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/outdoor/" class="nav-link p-0">
                    Outdoor
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-shader/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-shader/"><h6>Unity Creativecore Shader</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-shader/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/glass/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/glass/" class="nav-link p-0">
                    Glass
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/shader-graph/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/shader-graph/" class="nav-link p-0">
                    Shader-Graph
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-beginner-code/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-beginner-code/"><h6>Unity Creator Kit Beginner Code</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-beginner-code/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-beginner-code/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-fps/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-fps/"><h6>Unity Creator Kit FPS</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-fps/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-fps/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-mythirdperson/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-mythirdperson/"><h6>Unity My Third Person</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-mythirdperson/init/" class="nav-item my-1">
                
                
                  <a href="/unity-mythirdperson/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-playground/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-playground/"><h6>Unity Playground</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-playground/record/" class="nav-item my-1">
                
                
                  <a href="/unity-playground/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-ui/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-ui/"><h6>Unity UI</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-ui/init/" class="nav-item my-1">
                
                
                  <a href="/unity-ui/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-vfx/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-vfx/"><h6>Unity VFX</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-vfx/init/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/bullet/" class="nav-link p-0">
                    bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rain/" class="nav-link p-0">
                    rain
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rock-rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rock-rain/" class="nav-link p-0">
                    Rock Rain
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/vue/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/vue/"><h6>Vue</h6></a>
        
    </li>
    <li data-nav-id="/web/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/web/"><h6>Web</h6></a>
        
    </li>
        </ul>
    </div>
</nav>


</div>
                <div class="docs-toc large order-lg-2 order-md-0 order-xs-1 col-12 col-lg-2 col-xl-2 position-sticky border-left"><div class="docs-toc">
	<nav id="TableOfContents">
  <ul>
    <li><a href="#依赖">依赖</a></li>
    <li><a href="#application">Application</a></li>
    <li><a href="#mapper">Mapper</a></li>
    <li><a href="#调用">调用</a></li>
    <li><a href="#日志">日志</a></li>
    <li><a href="#insert">insert</a></li>
    <li><a href="#update">update</a></li>
    <li><a href="#自动填充">自动填充</a></li>
    <li><a href="#乐观锁">乐观锁</a></li>
    <li><a href="#select">select</a></li>
    <li><a href="#分页查询">分页查询</a></li>
    <li><a href="#delete">delete</a></li>
    <li><a href="#逻辑删除">逻辑删除</a></li>
    <li><a href="#性能分析插件">性能分析插件</a></li>
    <li><a href="#wrapper">wrapper</a></li>
    <li><a href="#代码自动生成器">代码自动生成器</a></li>
  </ul>
</nav>
</div>
</div>
                <div class="main col-12 order-1 col-md-9 col-lg-10 col-xl-8 py-3">
                

<div class="d-flex flex-column">
    <h1 class="js-title">Mybatis Plus</h1>
    <div class="d-flex align-items-center">
        
    </div>
</div>

<hr>


<h2 id="依赖">依赖</h2>
<p>参见官网，确认版本号，下文是与Spring Boot结合使用</p>
<h2 id="application">Application</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">org.mybatis.spring.annotation.MapperScan</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">@MapperScan</span><span style="color:#111">(</span><span style="color:#d88200">&#34;com.a.b.c.mapper&#34;</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MyApplication</span>
</span></span></code></pre></div><h2 id="mapper">Mapper</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.core.mapper.BaseMapper</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">@Repository</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">interface</span> <span style="color:#75af00">UserMapper</span> <span style="color:#00a8c8">extends</span> <span style="color:#111">BaseMapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span>
</span></span></code></pre></div><h2 id="调用">调用</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75af00">@Autowired</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">private</span> <span style="color:#111">UserMapper</span> <span style="color:#111">userMapper</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">List</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">users</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectList</span><span style="color:#111">(</span><span style="color:#00a8c8">null</span><span style="color:#111">);</span> <span style="color:#75715e">// 不带条件构造器的全查询</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="日志">日志</h2>
<p>mybatis-plus.configuration.log-imple = a.b.c</p>
<h2 id="insert">insert</h2>
<p>存在主键（id）生成策略，有uuid、自增id、雪花算法等等，参见官网</p>
<p>如果用自增id，需要数据库设置自增</p>
<p>IdType.INPUT，是需要手动设置id</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.annotation.IdType</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.annotation.TableId</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">User</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableId</span><span style="color:#111">(</span><span style="color:#111">type</span> <span style="color:#f92672">=</span> <span style="color:#111">IdType</span><span style="color:#111">.</span><span style="color:#75af00">ID_WORKER</span><span style="color:#111">)</span> <span style="color:#75715e">// 雪花算法的id</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Long</span> <span style="color:#111">id</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">User</span> <span style="color:#111">user</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">User</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// user.setX(&#34;x&#34;)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 另外可以不用setId，框架会自动生成</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">int</span> <span style="color:#111">res</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">insert</span><span style="color:#111">(</span><span style="color:#111">user</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#75af00">id</span> <span style="color:#75715e">// 并且id会自动回填</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="update">update</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">User</span> <span style="color:#111">user</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">User</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#75af00">setX</span><span style="color:#111">(</span><span style="color:#d88200">&#34;y&#34;</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// user.setX(&#34;x&#34;)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">int</span> <span style="color:#111">res</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">updateById</span><span style="color:#111">(</span><span style="color:#111">user</span><span style="color:#111">);</span> <span style="color:#75715e">// 会自动拼接sql set x?. y=?</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="自动填充">自动填充</h2>
<p>gmt_create、gmt_modified：数据库中都是datetime类型，Java里面都是Date类型</p>
<ul>
<li>数据库实现（不建议采用）：默认值为CURRENT_TIMESTAMP，gmt_modified勾选“更新”</li>
<li>代码实现，如下</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.annotation.IdType</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.annotation.TableId</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">User</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableId</span><span style="color:#111">(</span><span style="color:#111">type</span> <span style="color:#f92672">=</span> <span style="color:#111">IdType</span><span style="color:#111">.</span><span style="color:#75af00">ID_WORKER</span><span style="color:#111">)</span> <span style="color:#75715e">// 雪花算法的id</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Long</span> <span style="color:#111">id</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtCreate</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT_UPDATE</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtModified</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">com.baomidou.mybatisplus.core.handlers.MetaObjectHandler</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#111">org.apache.ibatis.reflection.MetaObject</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">@Component</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MyMetaObjectHandler</span> <span style="color:#00a8c8">implements</span> <span style="color:#111">MetaObjectHandler</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Override</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#75af00">insertFill</span><span style="color:#111">(</span><span style="color:#111">MetaObject</span> <span style="color:#111">metaObject</span><span style="color:#111">)</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">this</span><span style="color:#111">.</span><span style="color:#75af00">setFieldValByName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;gmtCreate&#34;</span><span style="color:#111">,</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Date</span><span style="color:#111">(),</span> <span style="color:#111">metaObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">this</span><span style="color:#111">.</span><span style="color:#75af00">setFieldValByName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;gmtModified&#34;</span><span style="color:#111">,</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Date</span><span style="color:#111">(),</span> <span style="color:#111">metaObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Override</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#75af00">updateFill</span><span style="color:#111">(</span><span style="color:#111">MetaObject</span> <span style="color:#111">metaObject</span><span style="color:#111">)</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">this</span><span style="color:#111">.</span><span style="color:#75af00">setFieldValByName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;gmtModified&#34;</span><span style="color:#111">,</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Date</span><span style="color:#111">(),</span> <span style="color:#111">metaObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="乐观锁">乐观锁</h2>
<ul>
<li>取出记录时，获取当前version</li>
<li>更新时，带上这个version</li>
<li>执行更新时，set version = newVersion where version = oldVersion</li>
<li>如果version不对，就更新失败</li>
</ul>
<p>先查当前version多少。处理多线程操作时并发问题。示意sql如下</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#00a8c8">update</span> <span style="color:#00a8c8">user</span> <span style="color:#00a8c8">set</span> <span style="color:#111">name</span> <span style="color:#f92672">=</span> <span style="color:#d88200">&#34;x&#34;</span><span style="color:#111">,</span> <span style="color:#00a8c8">version</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">version</span> <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">where</span> <span style="color:#111">id</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span> <span style="color:#00a8c8">and</span> <span style="color:#00a8c8">version</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">User</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableId</span><span style="color:#111">(</span><span style="color:#111">type</span> <span style="color:#f92672">=</span> <span style="color:#111">IdType</span><span style="color:#111">.</span><span style="color:#75af00">ID_WORKER</span><span style="color:#111">)</span> <span style="color:#75715e">// 雪花算法的id</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Long</span> <span style="color:#111">id</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtCreate</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT_UPDATE</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtModified</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Version</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Integer</span> <span style="color:#111">version</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75af00">@Configuration</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MybatisPlusConfig</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Bean</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">OptimisticLockerInterceptor</span> <span style="color:#75af00">optimisticLockerInterceptor</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">return</span> <span style="color:#00a8c8">new</span> <span style="color:#111">OptimisticLockerInterceptor</span><span style="color:#111">();</span> <span style="color:#75715e">// 乐观锁插件</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">User</span> <span style="color:#111">user</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectById</span><span style="color:#111">(</span><span style="color:#111">1</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#75af00">setX</span><span style="color:#111">(</span><span style="color:#d88200">&#34;y&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">int</span> <span style="color:#111">res</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">updateById</span><span style="color:#111">(</span><span style="color:#111">user</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="select">select</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">List</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">users</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectBatchIds</span><span style="color:#111">(</span><span style="color:#111">Arrays</span><span style="color:#111">.</span><span style="color:#75af00">asList</span><span style="color:#111">(</span><span style="color:#111">1</span><span style="color:#111">,</span><span style="color:#111">2</span><span style="color:#111">,</span><span style="color:#111">3</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">Map</span><span style="color:#f92672">&lt;</span><span style="color:#111">String</span><span style="color:#111">,</span><span style="color:#111">Object</span><span style="color:#f92672">&gt;</span> <span style="color:#111">map</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">HashMap</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">map</span><span style="color:#111">.</span><span style="color:#75af00">put</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;x&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">List</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">users2</span> <span style="color:#f92672">=</span> <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectBymap</span><span style="color:#111">(</span><span style="color:#111">map</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="分页查询">分页查询</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75af00">@Configuration</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MybatisPlusConfig</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Bean</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">PaginationInterceptor</span> <span style="color:#75af00">paginationInterceptor</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">PaginationInterceptor</span> <span style="color:#111">paginationInterceptor</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">OptimisticLockerInterceptor</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// paginationInterceptor 有些配置，参看官网</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">return</span> <span style="color:#111">paginationInterceptor</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">Page</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">page</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Page</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">(</span><span style="color:#111">1</span><span style="color:#111">,</span> <span style="color:#111">5</span><span style="color:#111">);</span> <span style="color:#75715e">// 第一页，一页五条数据</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectPage</span><span style="color:#111">(</span><span style="color:#111">page</span><span style="color:#111">,</span> <span style="color:#00a8c8">null</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">List</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">users</span> <span style="color:#f92672">=</span> <span style="color:#111">page</span><span style="color:#111">.</span><span style="color:#75af00">getRecords</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">Long</span> <span style="color:#111">total</span> <span style="color:#f92672">=</span> <span style="color:#111">page</span><span style="color:#111">.</span><span style="color:#75af00">getTotal</span><span style="color:#111">();</span> <span style="color:#75715e">// select count(1) from user</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="delete">delete</h2>
<ul>
<li>deleteById</li>
<li>deleteBatchIds</li>
<li>deleteByMap</li>
<li>delete(Wrapper<code>&lt;User&gt;</code> wrapper)</li>
</ul>
<h2 id="逻辑删除">逻辑删除</h2>
<p>添加deleted字段0表示未删，1表示已删</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">User</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableId</span><span style="color:#111">(</span><span style="color:#111">type</span> <span style="color:#f92672">=</span> <span style="color:#111">IdType</span><span style="color:#111">.</span><span style="color:#75af00">ID_WORKER</span><span style="color:#111">)</span> <span style="color:#75715e">// 雪花算法的id</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Long</span> <span style="color:#111">id</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtCreate</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableField</span><span style="color:#111">(</span><span style="color:#111">fill</span> <span style="color:#f92672">=</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT_UPDATE</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Date</span> <span style="color:#111">gmtModified</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Version</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Integer</span> <span style="color:#111">version</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@TableLogic</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">private</span> <span style="color:#111">Integer</span> <span style="color:#111">deleted</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75af00">@Configuration</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MybatisPlusConfig</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Bean</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">ISqlInjector</span> <span style="color:#75af00">sqlInjector</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">return</span> <span style="color:#00a8c8">new</span> <span style="color:#111">ISqlInjector</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><p>application.properties:</p>
<pre tabindex="0"><code> mybatis-plus.global-config.db-config.logic-delete-value=1
 mybatis-plus.global-config.db-config.logic-not-delete-value=0
</code></pre><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">deleteById</span><span style="color:#111">(</span><span style="color:#111">1</span><span style="color:#111">);</span> <span style="color:#75715e">// 实际会是 update user set deleted = 1 where id = 1 and deleted = 0</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="性能分析插件">性能分析插件</h2>
<p>spring.profiles.active = dev</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#75af00">@Configuration</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">MybatisPlusConfig</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Profile</span><span style="color:#111">({</span><span style="color:#d88200">&#34;dev&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;test&#34;</span><span style="color:#111">})</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75af00">@Bean</span>
</span></span><span style="display:flex;"><span>  <span style="color:#00a8c8">public</span> <span style="color:#111">PerformanceInterceptor</span> <span style="color:#75af00">performanceInterceptor</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">PerformanceInterceptor</span> <span style="color:#111">performanceInterceptor</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">PerformanceInterceptor</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">performanceInterceptor</span><span style="color:#111">.</span><span style="color:#75af00">setMaxTime</span><span style="color:#111">(</span><span style="color:#111">100</span><span style="color:#111">);</span> <span style="color:#75715e">// 设置SQL执行的最大时间，如果超过了则不执行</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">performanceInterceptor</span><span style="color:#111">.</span><span style="color:#75af00">setFormat</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span> <span style="color:#75715e">// sql格式化</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">return</span> <span style="color:#111">performanceInterceptor</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="wrapper">wrapper</h2>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test1</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">wrapper</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">wrapper</span><span style="color:#111">.</span><span style="color:#75af00">isNotNull</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name&#34;</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">.</span><span style="color:#75af00">isNotNull</span><span style="color:#111">(</span><span style="color:#d88200">&#34;email&#34;</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">.</span><span style="color:#75af00">ge</span><span style="color:#111">(</span><span style="color:#d88200">&#34;age&#34;</span><span style="color:#111">,</span> <span style="color:#111">12</span><span style="color:#111">);</span> <span style="color:#75715e">// 查name、email不等于空，且age大于等于12的</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectList</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span> <span style="color:#75715e">// 查多个</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectOne</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span>  <span style="color:#75715e">// 查一个</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test2</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">wrapper</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">wrapper</span><span style="color:#111">.</span><span style="color:#75af00">between</span><span style="color:#111">(</span><span style="color:#d88200">&#34;age&#34;</span><span style="color:#111">,</span> <span style="color:#111">20</span><span style="color:#111">,</span> <span style="color:#111">30</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">.</span><span style="color:#75af00">eq</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;x&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 查name ## x、且age在20到30区间</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectCount</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span> <span style="color:#75715e">// 查数量</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test3</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">wrapper</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">wrapper</span><span style="color:#111">.</span><span style="color:#75af00">notLike</span><span style="color:#111">(</span><span style="color:#d88200">&#34;name&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;e&#34;</span><span style="color:#111">)</span> <span style="color:#75715e">// name不包含e</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">.</span><span style="color:#75af00">likeRight</span><span style="color:#111">(</span><span style="color:#d88200">&#34;email&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;t&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// emial以t右开头的 t%</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectMaps</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test4</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">wrapper</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">wrapper</span><span style="color:#111">.</span><span style="color:#75af00">inSql</span><span style="color:#111">(</span><span style="color:#d88200">&#34;id&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;select id from user where id &lt; 3&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 子查询 ... where id in (select id from user where id &lt; 3)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectObjs</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">void</span> <span style="color:#75af00">test5</span><span style="color:#111">()</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;</span><span style="color:#111">User</span><span style="color:#f92672">&gt;</span> <span style="color:#111">wrapper</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">QueryWrapper</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">wrapper</span><span style="color:#111">.</span><span style="color:#75af00">orderByDesc</span><span style="color:#111">(</span><span style="color:#d88200">&#34;id&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// id降序</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">userMapper</span><span style="color:#111">.</span><span style="color:#75af00">selectList</span><span style="color:#111">(</span><span style="color:#111">wrapper</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="代码自动生成器">代码自动生成器</h2>
<p>对应表生成各个类（文件源码），下文的strategy.setInclue(&ldquo;user&rdquo;, &ldquo;school&rdquo;);</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">static</span> <span style="color:#00a8c8">void</span> <span style="color:#75af00">main</span><span style="color:#111">(</span><span style="color:#111">String</span><span style="color:#f92672">[]</span> <span style="color:#111">args</span><span style="color:#111">)</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 创建 代码自动生成器</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">AutoGenerator</span> <span style="color:#111">mpg</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">AutoGenerator</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 全局配置</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">GlobalConfig</span> <span style="color:#111">gc</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">GlobalCOnfig</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">String</span> <span style="color:#111">projectPath</span> <span style="color:#f92672">=</span> <span style="color:#111">System</span><span style="color:#111">.</span><span style="color:#75af00">getProperty</span><span style="color:#111">(</span><span style="color:#d88200">&#34;user.dir&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setOutputDir</span><span style="color:#111">(</span><span style="color:#111">projectPath</span> <span style="color:#f92672">+</span> <span style="color:#d88200">&#34;/src/main/java&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setAuthor</span><span style="color:#111">(</span><span style="color:#d88200">&#34;xx&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 文件作者</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setOpen</span><span style="color:#111">(</span><span style="color:#00a8c8">false</span><span style="color:#111">);</span> <span style="color:#75715e">// 不打开资源管理器</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setFileOverride</span><span style="color:#111">(</span><span style="color:#00a8c8">false</span><span style="color:#111">);</span> <span style="color:#75715e">// 不覆盖</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setServiceName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;%sService&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 去Service的I前缀</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setIdType</span><span style="color:#111">(</span><span style="color:#111">IdType</span><span style="color:#111">.</span><span style="color:#75af00">ID_WORKER</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setDateType</span><span style="color:#111">(</span><span style="color:#111">DateType</span><span style="color:#111">.</span><span style="color:#75af00">ONLY_DATE</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">gc</span><span style="color:#111">.</span><span style="color:#75af00">setSwagger2</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">mpg</span><span style="color:#111">.</span><span style="color:#75af00">setGlobalConfig</span><span style="color:#111">(</span><span style="color:#111">gc</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 设置数据源</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">DataSourceConfig</span> <span style="color:#111">dsc</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">DataSourceConfig</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">dsc</span><span style="color:#111">.</span><span style="color:#75af00">setUrl</span><span style="color:#111">(</span><span style="color:#d88200">&#34;jdbc:mysql://localhost:3306/mydb&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">dec</span><span style="color:#111">.</span><span style="color:#75af00">setDriverName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;com.mysql.cj.jdbc.Driver&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">dec</span><span style="color:#111">.</span><span style="color:#75af00">setUserName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;root&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">dec</span><span style="color:#111">.</span><span style="color:#75af00">setPassword</span><span style="color:#111">(</span><span style="color:#d88200">&#34;123456&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">dsc</span><span style="color:#111">.</span><span style="color:#75af00">setDbType</span><span style="color:#111">(</span><span style="color:#111">DbType</span><span style="color:#111">.</span><span style="color:#75af00">MYSQL</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">mpg</span><span style="color:#111">.</span><span style="color:#75af00">setDataSource</span><span style="color:#111">(</span><span style="color:#111">dsc</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 包的配置</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">PackageConfig</span> <span style="color:#111">pc</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">PackageConfig</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setModuleName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;blog&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setParent</span><span style="color:#111">(</span><span style="color:#d88200">&#34;com.h&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setEntity</span><span style="color:#111">(</span><span style="color:#d88200">&#34;entity&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setMapper</span><span style="color:#111">(</span><span style="color:#d88200">&#34;mapper&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setService</span><span style="color:#111">(</span><span style="color:#d88200">&#34;service&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">pc</span><span style="color:#111">.</span><span style="color:#75af00">setController</span><span style="color:#111">(</span><span style="color:#d88200">&#34;controller&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">mpg</span><span style="color:#111">.</span><span style="color:#75af00">setPackageInfo</span><span style="color:#111">(</span><span style="color:#111">pc</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 策略配置</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">StrategyConfig</span> <span style="color:#111">strategy</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">StrategyConfig</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setInclue</span><span style="color:#111">(</span><span style="color:#d88200">&#34;user&#34;</span><span style="color:#111">,</span> <span style="color:#d88200">&#34;school&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 设置要映射的表名</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setNaming</span><span style="color:#111">(</span><span style="color:#111">NamingStrategy</span><span style="color:#111">.</span><span style="color:#75af00">underline_to_camel</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setColumnNaming</span><span style="color:#111">(</span><span style="color:#111">NamingStrategy</span><span style="color:#111">.</span><span style="color:#75af00">underline_to_camel</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setSuperEntityClass</span><span style="color:#111">(</span><span style="color:#d88200">&#34;没父类的话就不用&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setEntityLombokModel</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setRestControllerStyle</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setLogicDeleteFieldName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;deleted&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 逻辑删除的字段</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">TableFill</span> <span style="color:#111">gmtCreate</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">TableFill</span><span style="color:#111">(</span><span style="color:#d88200">&#34;gmt_create&#34;</span><span style="color:#111">,</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT</span><span style="color:#111">);</span> <span style="color:#75715e">// 自动填充</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">TableFill</span> <span style="color:#111">gmtModified</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">TableFill</span><span style="color:#111">(</span><span style="color:#d88200">&#34;gmt_modified&#34;</span><span style="color:#111">,</span> <span style="color:#111">FieldFill</span><span style="color:#111">.</span><span style="color:#75af00">INSERT_UPDATE</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">List</span><span style="color:#f92672">&lt;</span><span style="color:#111">TableFill</span><span style="color:#f92672">&gt;</span> <span style="color:#111">tableFills</span> <span style="color:#f92672">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">ArrayList</span><span style="color:#f92672">&lt;&gt;</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">tableFills</span><span style="color:#111">.</span><span style="color:#75af00">add</span><span style="color:#111">(</span><span style="color:#111">gmtCreate</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">tableFills</span><span style="color:#111">.</span><span style="color:#75af00">add</span><span style="color:#111">(</span><span style="color:#111">gmtModified</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setTableFillList</span><span style="color:#111">(</span><span style="color:#111">tableFills</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setVersionFieldName</span><span style="color:#111">(</span><span style="color:#d88200">&#34;version&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 乐观锁</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setRestControllerStyle</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">strategy</span><span style="color:#111">.</span><span style="color:#75af00">setControllerMappingHyphenStyle</span><span style="color:#111">(</span><span style="color:#00a8c8">true</span><span style="color:#111">);</span> <span style="color:#75715e">// localhost:8080/hello_id_2</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">mpg</span><span style="color:#111">.</span><span style="color:#75af00">setStrategy</span><span style="color:#111">(</span><span style="color:#111">strategy</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// 执行</span>
</span></span><span style="display:flex;"><span>  <span style="color:#111">mpg</span><span style="color:#111">.</span><span style="color:#75af00">execute</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div>

    


                    
                    <div class="row"></div> 

                </div>

            </div> 

        </div> 
<script src="/lib/jquery.min.js"></script> 
<script src="/lib/popper.min.js"></script> 

<script src="/js/bootstrap.min.js"></script> 


<script type="text/javascript" src="/plugins/lunr.min.js"></script>
<script type="text/javascript" src="/plugins/auto-complete.js"></script>
<link href="/plugins/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
  
      var baseurl = "\/";
  
</script>
<script type="text/javascript" src="/plugins/search.js"></script>

<script type="text/javascript" src="/plugins/favorites.js"></script>


<script type="text/javascript" src="/plugins/clipboard.js"></script>
<script>
  new ClipboardJS('.btn');
</script>
</body>
</html>
